<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Form_validation extends CI_Form_validation 
{

	public function __construct($rules = array())
	{
		parent::__construct($rules);
		$this->CI->lang->load('MY_form_validation');
	}
	
	public function alpha_dash_space($str)
	{
		return ( ! preg_match("/^([-a-z0-9_ ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function alpha_space($str)
	{
		return ( ! preg_match("/^([a-z ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function alphanum_space($str)
	{
		return ( ! preg_match("/^([a-z0-9 ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function text_all($str)
	{
		return ( ! preg_match("/^([-a-z0-9_#,.!& ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function enumeration($str)
	{
		return ( ! preg_match("/^([a-z0-9, ])+$/i", $str)) ? FALSE : TRUE;
	}
	
	public function check_student_nationality()
	{
		if(strtolower($this->CI->input->post('child_nationality')) !== 'filipino')
		{
			if($this->CI->input->post('nationality_ssp_number') AND 
			   $this->CI->input->post('nationality_visa_status') AND
			   $this->CI->input->post('nationality_auth_stay') AND
			   $this->CI->input->post('nationality_passport_no') AND
			   $this->CI->input->post('nationality_icard_no') AND
			   $this->CI->input->post('nationality_date_issued')
			  )
			  {
				return TRUE;
			  }else{
				return FALSE;
			  }
		}else{
			return TRUE;
		}
	}
	
	function datechecker($date_from_input)
	{
		//Date From Input must be m/d/Y
	
		$date = DateTime::createFromFormat('m/d/Y', $date_from_input);
		if($date !== FALSE)
		{
			$d_e = explode('/',$date->format('m/d/Y'));

			if($date AND checkdate($d_e[0],$d_e[1],$d_e[2]))
			{
				return TRUE;
			}else{
				return FALSE;
			}
		}else{
			return FALSE;
		}
	}
 }


?> 